﻿using Entity.Front_Desk;
using Hotel.Models;
using IHotelBLL.IEmployeeBLL;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Hotel.Controllers.Employee.Employee
{
    public class EmployeeController : Controller
    {
        ResultModel result = new ResultModel();
        IFrontDeskBLL _frontDeskBLL;
        public EmployeeController(IFrontDeskBLL frontDeskBLL)
        {
            _frontDeskBLL = frontDeskBLL;
        }
        public IActionResult Login(string employeeNo, string password)
        {
            var employee = _frontDeskBLL.Login(employeeNo, password, out string msg);
            result.Msg = msg;
            if (employee != null)
            {
                result.IsSuccess = true;
                HttpContext.Session.SetString("employeeId", employee.Id);
                HttpContext.Session.SetString("employeeNo", employeeNo);
                result.Data = employee;
            }
            return Json(result);
        }
        public IActionResult GetEmployee(int page,int limit)
        {
            var res = new
            {
                code = 0,
                data = _frontDeskBLL.GetFrontDesks(page, limit, out int count),
                count,
            };
            return Json(res);
        }
        public IActionResult CreateEmployee(FrontDesk frontDesk)
        {
            if (frontDesk.EmployeeNo is null)
            {
                result.Msg = "员工编号不能为空";
                return Json(result);
            }
            if (frontDesk.EmployeeName is null)
            {
                result.Msg = "姓名不能为空";
                return Json(result);
            }
            if (frontDesk.Password is null)
            {
                result.Msg = "密码不能为空";
                return Json(result);
            }
            result.IsSuccess = _frontDeskBLL.CreatFrontDeskInfo(frontDesk, out string msg);
            result.Msg = msg;         
            return Json(result);
        }
        public IActionResult UpdateEmployee(FrontDesk frontDesk)
        {
            result.IsSuccess = _frontDeskBLL.UpdateFrontDeskInfo(frontDesk, out string msg);
            result.Msg = msg;
            return Json(result);
        }
        public IActionResult DeleteEmployeee(string id)
        {
            if (id == null)
            {
                result.Msg = "Id不能为空";
                return Json(result);
            }
            result.IsSuccess = _frontDeskBLL.DeleteFrontDeskInfo(id, out string msg);
            result.Msg = msg;
            return Json(result);
        }
    }
}
